/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Forms;

import BLL.BLLHoSoKhamBenh;
import DTO.DTOHoSoKhamBenh;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Documents
 */
public class HoSoKhamBenh extends javax.swing.JFrame {
    BLLHoSoKhamBenh bllHS = new BLLHoSoKhamBenh();
    DefaultTableModel modelHS;
    /**
     * Creates new form HoSoKhamBenh
     */
    public HoSoKhamBenh(String maBN) {
        initComponents();
        DanhSachHoSo(maBN);
    }

    

    

    //lay du lieu dua vao bang
     private void DanhSachHoSo(String maBN) {
         try {
            modelHS = new DefaultTableModel();
            String muc[] = {"Mã hồ sơ", "Họ tên bệnh nhân", "Ngày khám", "Phòng khám", "Chẩn đoán"};
            modelHS.setColumnIdentifiers(muc);
            for(DTOHoSoKhamBenh dtoHS: bllHS.LayHSTheoMaBN(maBN)){
                modelHS.addRow(new Object[]{dtoHS.getMaHS(), dtoHS.getDtoBN().getHoten(), dtoHS.getNgayKham(), 
                    dtoHS.getDtoPK().getTenpk(), dtoHS.getChanDoan()});
            }
            jTbHSKhamBenh.setModel(modelHS);
        } catch (Exception e) {
            System.err.print("Lấy dữ liệu không thành công");
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jpnlChiTiet = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jtxtMaBN = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtxtHoTen = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jrabtnNam = new javax.swing.JRadioButton();
        jrabtnNu = new javax.swing.JRadioButton();
        jLabel10 = new javax.swing.JLabel();
        jtxtMaHS = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jtxtNgayKham = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jtxtPhongKham = new javax.swing.JTextField();
        jtxtBacSi = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jrabtnCo = new javax.swing.JRadioButton();
        jrabtnKhong = new javax.swing.JRadioButton();
        jtxtMaBH = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jckbxVuotTuyen = new javax.swing.JCheckBox();
        jLabel21 = new javax.swing.JLabel();
        jtxtNgayTaiKham = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jtxtChanDoan = new javax.swing.JTextField();
        jtxtNgayHetHan = new javax.swing.JTextField();
        jpnlTuyChon = new javax.swing.JPanel();
        jbtnTim = new javax.swing.JButton();
        jtxtTim = new javax.swing.JTextField();
        jbtnXoa = new javax.swing.JButton();
        jpnlHoSo = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTbHSKhamBenh = new javax.swing.JTable();

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 102, 0));
        jLabel1.setText("HỒ SƠ KHÁM BỆNH");

        jpnlChiTiet.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(255, 255, 255), new java.awt.Color(0, 0, 102)), "Thông tin chi tiết"));

        jLabel2.setText("Mã BN");

        jtxtMaBN.setEnabled(false);

        jLabel3.setText("Họ tên");

        jtxtHoTen.setEnabled(false);
        jtxtHoTen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtHoTenActionPerformed(evt);
            }
        });

        jLabel4.setText("Giới tính");

        buttonGroup1.add(jrabtnNam);
        jrabtnNam.setText("Nam");
        jrabtnNam.setEnabled(false);

        buttonGroup1.add(jrabtnNu);
        jrabtnNu.setText("Nữ");
        jrabtnNu.setEnabled(false);

        jLabel10.setText("Mã hồ sơ");

        jtxtMaHS.setEnabled(false);

        jLabel11.setText("Ngày khám");

        jtxtNgayKham.setEnabled(false);
        jtxtNgayKham.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtNgayKhamActionPerformed(evt);
            }
        });

        jLabel12.setText("Ngày tái khám");

        jLabel13.setText("Bác sĩ");

        jtxtPhongKham.setEnabled(false);

        jtxtBacSi.setEnabled(false);

        jLabel18.setText("Phòng khám");

        jLabel19.setText("BHYT");

        jrabtnCo.setText("Có");
        jrabtnCo.setEnabled(false);

        jrabtnKhong.setText("Không");
        jrabtnKhong.setEnabled(false);

        jtxtMaBH.setEnabled(false);

        jLabel20.setText("Mã BHYT");

        jckbxVuotTuyen.setText("Vượt tuyến");
        jckbxVuotTuyen.setEnabled(false);

        jLabel21.setText("Ngày hết hạn");

        jtxtNgayTaiKham.setEnabled(false);

        jLabel22.setText("Chẩn đoán");

        jtxtChanDoan.setEnabled(false);

        jtxtNgayHetHan.setEnabled(false);

        javax.swing.GroupLayout jpnlChiTietLayout = new javax.swing.GroupLayout(jpnlChiTiet);
        jpnlChiTiet.setLayout(jpnlChiTietLayout);
        jpnlChiTietLayout.setHorizontalGroup(
            jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnlChiTietLayout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtChanDoan, javax.swing.GroupLayout.PREFERRED_SIZE, 645, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jpnlChiTietLayout.createSequentialGroup()
                        .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel19))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                                .addComponent(jtxtMaHS, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtxtNgayKham, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                                .addComponent(jrabtnCo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrabtnKhong)
                                .addGap(18, 18, 18)
                                .addComponent(jckbxVuotTuyen)
                                .addGap(31, 31, 31)
                                .addComponent(jLabel20)))
                        .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jtxtMaBH, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(43, 43, 43)
                                .addComponent(jLabel21)
                                .addGap(18, 18, 18)
                                .addComponent(jtxtNgayHetHan, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtxtNgayTaiKham, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(31, 31, 31)
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jtxtPhongKham, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(58, Short.MAX_VALUE))
                    .addGroup(jpnlChiTietLayout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jtxtMaBN, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtxtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jrabtnNam, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jrabtnNu)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtxtBacSi, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        jpnlChiTietLayout.setVerticalGroup(
            jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jtxtMaBN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(jtxtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jrabtnNu)
                        .addComponent(jrabtnNam)
                        .addComponent(jLabel4)
                        .addComponent(jLabel13)
                        .addComponent(jtxtBacSi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11)
                        .addComponent(jtxtNgayKham, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jtxtMaHS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel12)
                        .addComponent(jtxtNgayTaiKham, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel18)
                        .addComponent(jtxtPhongKham, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(jrabtnCo)
                    .addComponent(jrabtnKhong)
                    .addComponent(jckbxVuotTuyen)
                    .addComponent(jLabel20)
                    .addComponent(jtxtMaBH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel21)
                    .addComponent(jtxtNgayHetHan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(jtxtChanDoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpnlTuyChon.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(0, 0, 102)), "Tùy chọn"));

        jbtnTim.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/IconsLandVista.png"))); // NOI18N
        jbtnTim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnTimActionPerformed(evt);
            }
        });

        jbtnXoa.setText("Xóa");
        jbtnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnXoaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpnlTuyChonLayout = new javax.swing.GroupLayout(jpnlTuyChon);
        jpnlTuyChon.setLayout(jpnlTuyChonLayout);
        jpnlTuyChonLayout.setHorizontalGroup(
            jpnlTuyChonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnlTuyChonLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtnTim, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtxtTim, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbtnXoa)
                .addGap(7, 7, 7))
        );
        jpnlTuyChonLayout.setVerticalGroup(
            jpnlTuyChonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlTuyChonLayout.createSequentialGroup()
                .addGroup(jpnlTuyChonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtTim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jpnlTuyChonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtnTim)
                        .addComponent(jbtnXoa)))
                .addGap(0, 3, Short.MAX_VALUE))
        );

        jpnlHoSo.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(0, 0, 102)), "Danh sách hồ sơ"));

        jTbHSKhamBenh.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTbHSKhamBenh.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTbHSKhamBenhMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTbHSKhamBenh);

        javax.swing.GroupLayout jpnlHoSoLayout = new javax.swing.GroupLayout(jpnlHoSo);
        jpnlHoSo.setLayout(jpnlHoSoLayout);
        jpnlHoSoLayout.setHorizontalGroup(
            jpnlHoSoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
            .addGroup(jpnlHoSoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jpnlHoSoLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1)
                    .addContainerGap()))
        );
        jpnlHoSoLayout.setVerticalGroup(
            jpnlHoSoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 281, Short.MAX_VALUE)
            .addGroup(jpnlHoSoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jpnlHoSoLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(284, 284, 284))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jpnlTuyChon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpnlHoSo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpnlChiTiet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jpnlChiTiet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpnlTuyChon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpnlHoSo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtxtHoTenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtHoTenActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtHoTenActionPerformed

    private void jtxtNgayKhamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtNgayKhamActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtNgayKhamActionPerformed

    private void jTbHSKhamBenhMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTbHSKhamBenhMouseClicked
         try {
            clearField();
            int maHS = Integer.valueOf(jTbHSKhamBenh.getValueAt(jTbHSKhamBenh.getSelectedRow(), 0).toString());
            DTOHoSoKhamBenh dtoHS = bllHS.LayHSTheoMa(maHS);
            if(dtoHS != null){
                jtxtMaBN.setText(dtoHS.getDtoBN().getMaBN());
                jtxtHoTen.setText(dtoHS.getDtoBN().getHoten());
                if("Nam".equals(dtoHS.getDtoBN().getGioitinh()))
                {
                    jrabtnNam.setSelected(true);
                }
                else
                    jrabtnNu.setSelected(true);
                jtxtBacSi.setText(dtoHS.getBacSi());
                jtxtMaHS.setText(String.valueOf(dtoHS.getMaHS()));
                jtxtNgayKham.setText(String.valueOf(dtoHS.getNgayKham()));
                jtxtNgayTaiKham.setText(String.valueOf(dtoHS.getNgayTaiKham()));
                jtxtPhongKham.setText(dtoHS.getDtoPK().getTenpk());
                //kiem tra co BHYT hay ko
                if(dtoHS.getDtoBN().getBHYT()==1)
                    jrabtnCo.setSelected(true);
                else
                    jrabtnKhong.setSelected(true); 
                //kiem tra vuot tuyen
                if(dtoHS.getDtoBN().getVuottuyen()==1)
                    jckbxVuotTuyen.setSelected(true);
                else
                    jckbxVuotTuyen.setSelected(false);
                jtxtMaBH.setText(dtoHS.getDtoBN().getMaBH());
                //kiem tra ngay het han BHYT
                if(dtoHS.getDtoBN().getNgayhethan() != null)
                    jtxtNgayHetHan.setText(dtoHS.getDtoBN().getNgayhethan().toString());
                jtxtChanDoan.setText(dtoHS.getChanDoan());
            } 
        }
            catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Lấy dữ liệu thất bại");
        }
    }//GEN-LAST:event_jTbHSKhamBenhMouseClicked

    private void jbtnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnXoaActionPerformed
        try{
            int dong[] = jTbHSKhamBenh.getSelectedRows();
            if(dong.length > 0){
                if(JOptionPane.showConfirmDialog(null, "Bạn có chắc muốn xóa?", "Thông báo", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION){
                    int dem = 0;
                    for(int i = dong.length - 1; i >= 0; i--){
                        int maHS = Integer.valueOf(jTbHSKhamBenh.getValueAt(dong[i], 0).toString());
                        bllHS.XoaHoSo(maHS);
                        modelHS.removeRow(dong[i]);
                        dem++;
                    }
                    if(dem==dong.length){
                        JOptionPane.showMessageDialog(null, "Đã xóa hồ sơ");
                    }
                }
            }
            else
                JOptionPane.showMessageDialog(null, "Vui lòng chọn mục muốn xóa");
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, "Bị lỗi, không thể xóa!");
        }
    }//GEN-LAST:event_jbtnXoaActionPerformed

    private void jbtnTimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnTimActionPerformed
        try {
            for (int i = modelHS.getRowCount() -1; i >= 0; i--) {
                modelHS.removeRow(i);
            }
            int tim = Integer.valueOf(jtxtTim.getText());
            ArrayList<DTOHoSoKhamBenh> dsHS = bllHS.TimHoSo(tim);
            for(DTOHoSoKhamBenh dtoHS : dsHS){
                modelHS.addRow(new Object[]{dtoHS.getMaHS(), dtoHS.getNgayKham(), dtoHS.getDtoPK().getTenpk(),
                        dtoHS.getChanDoan()});
            }
        } catch (Exception e) {
        }
    }//GEN-LAST:event_jbtnTimActionPerformed

    private void clearField(){
        jtxtMaBN.setText("");
        jtxtHoTen.setText("");
        jtxtBacSi.setText("");
        jtxtMaHS.setText("");
        jtxtNgayKham.setText("");
        jtxtNgayTaiKham.setText("");
        jtxtPhongKham.setText("");
        jtxtMaBH.setText("");
        jtxtNgayHetHan.setText("");
        jtxtChanDoan.setText("");
    }
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HoSoKhamBenh.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HoSoKhamBenh.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HoSoKhamBenh.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HoSoKhamBenh.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
//                new HoSoKhamBenh().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTbHSKhamBenh;
    private javax.swing.JButton jbtnTim;
    private javax.swing.JButton jbtnXoa;
    private javax.swing.JCheckBox jckbxVuotTuyen;
    private javax.swing.JPanel jpnlChiTiet;
    private javax.swing.JPanel jpnlHoSo;
    private javax.swing.JPanel jpnlTuyChon;
    private javax.swing.JRadioButton jrabtnCo;
    private javax.swing.JRadioButton jrabtnKhong;
    private javax.swing.JRadioButton jrabtnNam;
    private javax.swing.JRadioButton jrabtnNu;
    private javax.swing.JTextField jtxtBacSi;
    private javax.swing.JTextField jtxtChanDoan;
    private javax.swing.JTextField jtxtHoTen;
    private javax.swing.JTextField jtxtMaBH;
    private javax.swing.JTextField jtxtMaBN;
    private javax.swing.JTextField jtxtMaHS;
    private javax.swing.JTextField jtxtNgayHetHan;
    private javax.swing.JTextField jtxtNgayKham;
    private javax.swing.JTextField jtxtNgayTaiKham;
    private javax.swing.JTextField jtxtPhongKham;
    private javax.swing.JTextField jtxtTim;
    // End of variables declaration//GEN-END:variables
}
